package com.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.DigestUtil;



public class MD5Salt {
	private static final String[] GOAL =
		{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
		private static String algorithm = "i3MLvl8fBa8="; // 加密方式
		private static String salt = "Oq1ZqieDhEglvkgy7JedUQ=="; // 盐值
		public static String getMD5(String object)
		{
			String result = null;
			try
			{
				algorithm=DES.decryptDES(algorithm);
				result=DigestUtil.md5Hex(addSalt(object));
			}
			catch (NoSuchAlgorithmException e)
			{
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return result.toUpperCase();
		}

		/**
		 * 在加密对象后加盐
		 * 
		 * @param object
		 * @return
		 */
		private static String addSalt(String object)
		{
			try {
				algorithm=DES.decryptDES(salt);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (object == null)
			{
				object = "";
			}
			if (salt == null || "".equals(salt))
			{
				return object;
			}
			else
			{
				return object + "{" + salt.toString() + "}";
			}
		}
//		86D84B2B160F6599B7AA6E584B798F64
		public static String  toMD5Salt(String password)
		{
			return MD5Salt.getMD5(password);
		}
//		public static void main(String[] args) {
//		System.out.println(MD5Salt.getMD5("123456"));
//		System.out.println( DigestUtil.md5Hex("123456"));	
//		}	
		public static String  toMD5HutoolSalt(String password)
		{
//			return DigestUtil.md5Hex(password);
			return MD5Salt.getMD5(password);
		}
}
